<div id="time-init">
    <div>
        <p>
            <span>当前时间: <span class="p-date">{{$date}}</span></span>
            <span class="text-red p-time"> {{$times}}</span>
        </p>
        <h1>
            <b>{{ $user['name'] }}: {{ $user['username'] }}</b>
        </h1>
    </div>
</div>

<script init="#time-init">
    Dcat.ready(function () {
        let getNumber = (t) => {
            return t <= 9 ? `0${t}` : t;
        };
        let getDateParse = (time = '') => {
            let date = time ? new Date(time) : new Date();
            return {
                year: date.getFullYear(),
                month: getNumber(date.getMonth() + 1),
                date: getNumber(date.getDate()),
                day: date.getDay(),
                hours: getNumber(date.getHours()),
                minutes: getNumber(date.getMinutes()),
                seconds: getNumber(date.getSeconds())
            };
        };
        let setTime = function () {
            setInterval(function () {
                let date = getDateParse();
                $(".p-time").html(`${date.hours}:${date.minutes}:${date.seconds}`);
            }, 1000);
        };
        setTime();
    });
</script>

